<?php

class Application_Form_Mutuelle extends Zend_Form {

    public function init() {
        /* Form Elements & Other Definitions Here ... */
    }

    public function __construct($formAction = "Enregistrer", $legende = 'Nouvelle') {

        $this->setDecorators(array('FormElements', 'Form')); // supprime la balise <dl>

        $decorators = array(
            'ViewHelper',
            'Errors',
            array('Description', array('tag' => 'p', 'class' => 'description')),
            array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'input')), // 3
            array('Label', array('tag' => null, 'class' => '')), // 2
            array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix')) // 1) exterieur
        );

        $noDecorators = array('ViewHelper');

        $id = new Zend_Form_Element_Hidden('id_mutuelle');
        $id->setBelongsTo('Mutuelle')
                ->addFilter('Int')
                ->addFilter('Null');

        $nom = new Zend_Form_Element_Text('raison_sociale');
        $nom->setLabel('Raison Sociale')
                ->setBelongsTo('Mutuelle')
                ->setRequired(true)
                ->setAttrib('class', 'xlarge')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');

        $email = new Zend_Form_Element_Text('email');
        $email->setLabel('eMail')
                ->setBelongsTo('Mutuelle')
                ->setRequired(false)
                ->addFilter('Null')
                ->addValidator('EmailAddress', true)
                ->setAttrib('class', 'xlarge')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');


        $urlBack = $this->getView()->url(array('controller' => 'mutuelle', 'action' => 'index'));
        $cancel = new Zend_Form_Element_Button('cancel');
        $cancel->setLabel('Annuler')
                ->setAttrib('class', 'btn')
                ->setAttrib('type', 'reset')
                ->setDecorators(array('ViewHelper'))
                ->setAttrib('onclick', 'window.location =\'' . $urlBack . '\' ');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel($formAction)
                ->setAttrib('id', 'submitbutton')
                ->setAttrib('class', 'btn primary');

        // Add Elements
        $this->addElements(array($id, $nom, $email, $cancel, $submit));

        // Subform Adresse
        $adresseSub = new Application_Form_SubForm_Adresse();

        $fiel_name = null;
        foreach ($adresseSub->getElements() as $name => $element) {
            $this->addElement($element);
            $fiel_name[] = $name;
        }


        $this->setElementDecorators(array('ViewHelper'), array('submit', 'cancel'));
        $this->setElementDecorators($decorators, array_merge(array('raison_sociale', 'email'), $fiel_name));
        $this->setElementDecorators($noDecorators, array('id_mutuelle', 'id_adresse'));

        // Patient Group
        $this->addDisplayGroup(
                array_merge(array('raison_sociale', 'email'), $fiel_name)
                , 'mutuelleGroup', array('legend' => $legende . " Mutuelle", '_style' => 'font-size:12px;'));

        $contact = $this->getDisplayGroup('mutuelleGroup');
        $contact->setDecorators(array(
            'FormElements',
            'Fieldset',
            array('HtmlTag', array('tag' => 'div', 'class' => 'span12', '_style' => 'width:40%;color:blue;')),
            array(array('rowspan' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))));

        // Buttons Group
        $this->addDisplayGroup(array('cancel', 'submit'), 'buttonGroupe');
        $this->buttonGroupe->removeDecorator('Label');
        $this->buttonGroupe->setDecorators(array(
            'FormElements',
            array('HtmlTag', array('tag' => 'div', 'class' => 'actions'))
        ));
    }

}

